package com.blb.exam.common.util;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * Spring的应用程序上下文工具
 */
@EnableAspectJAutoProxy
@ComponentScan(basePackages = "com.blb")
@Configuration
public class SpringUtils {

    //应用程序上下文
    private static AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringUtils.class);

    /**
     * 返回对象
     * @param tClass
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> tClass){
        return context.getBean(tClass);
    }
}
